
// 聚合数据，万年历
export default class Calendar {
  constructor () {
    this.date = ''
  }
  init ({bot, msg}) {
    this.date = this.getCurrentDay()
    this.getDayInfo(bot, msg)
  }
  getCurrentDay () {
    let date = new Date()
    let year = date.getFullYear()
    let month = date.getMonth() + 1
    let day = date.getDate()
    return year + '-' + month + '-' + day
  }

  getDayInfo (bot, msg) {
    bot.request({
      method: 'GET',
      url: 'http://v.juhe.cn/calendar/day',
      params: {
        key: '113f31a86a232bcc5df426e6f663a67e',
        date: this.date
      }
    }).then(res => {
      const resObj = res.data.result.data
      const replyStr = `${resObj.date} ${resObj.weekday}\n${resObj.lunar}\n${resObj.lunarYear} ${resObj.animalsYear}\n\n宜●${resObj.suit}\n忌●${resObj.avoid}`
      bot.sendMsg(replyStr, msg.FromUserName)
      bot.emit('exitGame', msg.FromUserName)
    })
  }
}
